//-----------------------------------------
//	VertexLighting
//-----------------------------------------

//------------------
//--- Parameters ---
float4x4 World;
float4x4 View;
float4x4 Projection;

//light properties
float4 lightColor = {0,0,1,1};
float3 lightDirection = {-1,-1,-1};
float4 ambientColor = 0.2;

//------------------
//--- Structures ---
struct VertexShaderInput
{
	float4 position : POSITION;
	float3 normal : NORMAL;
};

struct VertexShaderOutput 
{
     float4 Position : POSITION;
     float4 Color : COLOR0;
};

struct PixelShaderInput
{
     float4 Color: COLOR0;
};

//--------------------
//--- VertexShader ---
VertexShaderOutput DiffuseLighting(VertexShaderInput input)
{

     VertexShaderOutput output;
     
     //transform the input position to the output
     output.Position = mul(mul(mul(input.position, World), View), Projection);
     
     float3 worldNormal =  mul(input.normal, World);
     
     float diffuseIntensity = saturate( dot(-lightDirection, worldNormal));

     float4 diffuseColor = lightColor * diffuseIntensity;
     
     
     output.Color = diffuseColor + ambientColor;
     diffuseColor.a = 1.0;

     return output;
}

//-------------------
//--- PixelShader ---
float4 SimplePixelShader(PixelShaderInput input) : COLOR
{
     return input.Color;
}

//------------------
//--- Techniques ---
technique VertexLighting
{
    pass P0
    {
          VertexShader = compile vs_2_0 DiffuseLighting();
          PixelShader = compile ps_2_0 SimplePixelShader();
    }
}